﻿using System;
using System.Collections.Generic;
using System.Linq;
using LoungeRepo.Contracts.Normalizer;
using LoungeRepo.Normalizer.DataStructures;

namespace LoungeRepo.Normalizer
{
    internal partial class ObjectGraphDenormalizer
    {
        private readonly EntityResolutionRequestDelegate resolveEntityReference;
        private readonly Dictionary<string, object> denormalizedObjectCache = new Dictionary<string, object>();


        public ObjectGraphDenormalizer(EntityResolutionRequestDelegate resolveEntityReference)
        {
            this.resolveEntityReference = resolveEntityReference;
        }


        public object Denormalize(INormalizedObject normalizedObject)
        {
            var denormalizedObject = Activator.CreateInstance(normalizedObject.ObjectType);
            this.denormalizedObjectCache.Add(normalizedObject.RefId, denormalizedObject);

            DenormalizeNonTransientFields(normalizedObject, denormalizedObject);

            return denormalizedObject;
        }
    }
}
